import axios from "axios"
import NProgress from "nprogress"
import 'nprogress/nprogress.css'


const Request = axios.create({
    baseURL: "/api",
    timeout: 10000,
})


Request.interceptors.request.use((config) => {
    NProgress.start()
    //每个请求携带token
    config.headers.token=localStorage.getItem("user_token")
    
    return config
})
Request.interceptors.response.use((res) => {
    NProgress.done()
    if(res.data.code===20000){
        return Promise.reject({
            message:res.data.msg,
            isLogin:false
        })
    }
    if(res.data.code!==10000){
        return Promise.reject({
            message:res.data.msg
        })
    }
    return res.data
}, (e) => {
    return Promise.reject(e)
})



export default Request